<?php
	require_once dirname(__FILE__) . "/../includes/config.php";
	require_once PHP_ROOTPATH.'/classes/database.php';
	// On prolonge la session
	session_start();
	
	$id_anim='';
	$code='';
	
	if(!isset($_SESSION['membre_id'])){
		header('Location: ../site.php');
		exit();
	}
	else{
		// On teste si la variable de session existe et contient une valeur
		if(empty($_SESSION['id_anim'])){
			// Si inexistante ou nulle, on redirige vers le formulaire de login
			header('Location: ./recherche.php');
			exit();
		}
		else{
			$id_anim=$_SESSION['id_anim'];
			$code=$_SESSION['code'];
		}
		
		$idconnect=Database::getInstance();
		$querytest = pg_query($idconnect,"SELECT * FROM droit_utilisateur WHERE id_droit = 6   and droit_utilisateur.id_user=".$_SESSION['membre_id']);
		$lecture_irm = pg_num_rows($querytest);
		$querytest = pg_query($idconnect,"SELECT * FROM droit_utilisateur WHERE id_droit = 7   and droit_utilisateur.id_user=".$_SESSION['membre_id']);
		$lecture_sequence = pg_num_rows($querytest);			 
		$query = pg_query($idconnect,"SELECT date_naissance FROM animal WHERE id_animal='".$id_anim."'");
		while ($back = pg_fetch_assoc($query)) {
			$_SESSION['date_n'] = $back["date_naissance"];
		}
		if( $lecture_irm == 0 && $lecture_sequence == 0){
			header('location: ./animal/animal.php');
		}
		else if($lecture_irm != 0){
			header('location: ./autres_tests/irm.php');
		}
		else if($lecture_sequence != 0){
			header('location: ./autres_tests/seq.php');
		}
	}
?>

